package com.cryptoneedle.garden.entity.garden.ods;

import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.garden.enums.OdsTranslateType;
import com.cryptoneedle.garden.key.ColumnKey;
import com.cryptoneedle.garden.key.OdsColumnTranslateKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: ODS-SourceColumn </p>
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "doris_column_translate")
@IdClass(OdsColumnTranslateKey.class)
@Comment("Doris-ODS列值翻译")
public class OdsColumnTranslate extends BaseEntity {

    /**
     * DorisColumn
     */

    @Id
    @Column(length = 512)
    @Comment("SourceCatalog 名称")
    private String catalogName;

    @Id
    @Column(length = 64)
    @Comment("SourceDatabase 名称")
    private String databaseName;

    @Id
    @Column(length = 64)
    @Comment("表名称")
    private String tableName;

    @Id
    @Column(length = 64)
    @Comment("列名称")
    private String columnName;

    @Id
    @Enumerated(EnumType.STRING)
    @Comment("翻译类型")
    private OdsTranslateType translateType;

    @Id
    @Comment("数据值")
    private String dataValue;

    @Comment("翻译值")
    private String translateValue;

    @Comment("排序")
    private Integer sequence;

    /**
     * Mapping Custom
     */

    public OdsColumnTranslateKey odsColumnTranslateKey() {
        return new OdsColumnTranslateKey(this.catalogName, this.databaseName, this.tableName, this.columnName, this.translateType, this.dataValue);
    }

    public ColumnKey columnKey() {
        return new ColumnKey(this.catalogName, this.databaseName, this.tableName, this.columnName);
    }

    public String odsColumnTranslateKeyString() {
        return odsColumnTranslateKey().toString();
    }
}